package com.digitalchina.lxnsy.viewholder;

import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.MyFeedbackListVO;
import com.digitalchina.lxnsy.toolkit.JointImageUrl;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.lzy.ninegrid.ImageInfo;
import com.lzy.ninegrid.NineGridView;
import com.lzy.ninegrid.preview.NineGridViewClickAdapter;

import java.util.ArrayList;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2018/3/15 14:28
 * 修改备注：
 * ================================================
 */

public class MyFeedbackListHolder extends BaseViewHolder<MyFeedbackListVO> {

    private TextView tvTime;
    private TextView tvTitle;
    private TextView tvState; // replyStatus:回复状态 0-待回复 1-已回复
    private LinearLayout layout;
    private NineGridView nineGridView;


    public MyFeedbackListHolder(ViewGroup parent) {
        super(parent, R.layout.item_my_feedback_list);
        tvTime = $(R.id.tv_time);
        tvTitle = $(R.id.tv_title);
        tvState = $(R.id.tv_state);
        layout = $(R.id.layout_imgs);
        nineGridView = $(R.id.nineGrid);
    }

    @Override
    public void setData(MyFeedbackListVO data) {
        super.setData(data);
        tvTime.setText(data.getCreateTime());
        tvTitle.setText(data.getFbContent());

        if (data.getReplyStatus() == 0) {
            tvState.setText("待回复");
            tvState.setTextColor(getContext().getResources().getColor(R.color.colorGray));
        } else {
            tvState.setText("已回复");
            tvState.setTextColor(getContext().getResources().getColor(R.color.app_color));
        }

        ArrayList<ImageInfo> imageInfo = new ArrayList<>();
        if (data.getFeedBackImgs() != null && data.getFeedBackImgs().size() > 0) {
//            layout.removeAllViews();
//            layout.removeAllViewsInLayout();
            nineGridView.setVisibility(View.VISIBLE);
            for (int i = 0; i < data.getFeedBackImgs().size(); i++) {
//                View view = LayoutInflater.from(getContext()).inflate(R.layout.view_image, null);
//                SimpleDraweeView sdv = view.findViewById(R.id.sdv_image);
//                FrescoUtil.showImageSmall(data.getFeedBackImgs().get(i).getImgID(), sdv);
//                layout.addView(view);
                ImageInfo info = new ImageInfo();
                info.setThumbnailUrl(JointImageUrl.smallImageUrl(data.getFeedBackImgs().get(i).getImgID()));
                info.setBigImageUrl(JointImageUrl.bigImageUrl(data.getFeedBackImgs().get(i).getImgID()));
                imageInfo.add(info);
            }
        } else {
            nineGridView.setVisibility(View.GONE);
        }

        nineGridView.setAdapter(new NineGridViewClickAdapter(getContext(), imageInfo));
    }
}
